package cn.lanca.esaypoi.c202204.week_4.thu;

import cn.lanca.esaypoi.c202204.week_3.v4.CommonA;
import cn.lanca.esaypoi.util.tool.ExcelUtil;
import org.springframework.util.StringUtils;

import java.io.IOException;
import java.util.List;

/**
 * project name:<font size = "1"><b>小芄健康数据运营平台</b></font><br>
 * file name:<font size = "1"><b> </b></font><br>
 * description:<font size = "1"><b> </b></font><br>
 * company name:<font size = "1"><b>小芄医药科技（成都）有限公司-研发中心</b></font><br>
 *
 * @author <a href="mail to: meihongliang@xiaowanjiankang.com" rel="nofollow">meihongliang<br>
 * @version 1.0.0<br>
 * @since [1] [2022/4/28 17:43] [meihongliang] [新建] <br>
 */
public class TestImg {
    public static void main(String[] args) throws IOException {
//        test();

    }

    private static void test() throws IOException {
//        List<CommonA> commonAS = ExcelUtil.readExcel("/Users/meihongliang/Downloads/A_xiaowan/download/B_女性常用OTC71_匹配上数据_12.xlsx", CommonA.class);
//        List<CommonA> commonAS = ExcelUtil.readExcel("/Users/meihongliang/Downloads/A_xiaowan/download/C_肛肠常用OTC64_匹配上数据_13.xlsx", CommonA.class);
        List<CommonA> commonAS = ExcelUtil.readExcel("/Users/meihongliang/Downloads/A_xiaowan/download/D_儿童常用OTC77_匹配上数据_28.xlsx", CommonA.class);
        System.out.println(commonAS.size());
        for (int m = 0; m < commonAS.size(); m++) {
            CommonA commonA = commonAS.get(m);
            String a18 = commonA.getA18();
            if (StringUtils.hasText(a18)) {
                String[] split = a18.split(",");
                System.out.println("第" + m + "条数据,图片数量:" + split.length);
                StringBuilder sb = new StringBuilder();
                for (int i = 0; i < split.length; i++) {
                    String url = split[i];
                    String s = commonA.getA21() + "_" + commonA.getA4() + "_" + (i + 1) + ".jpg";
                    try {
                        ExcelUtil.downloadPicture(url, "/Users/meihongliang/Downloads/A_xiaowan/download/D_儿童常用OTC/" + s);
                        sb.append(s).append(";");
                    } catch (Exception e) {
                        System.out.println(e.getMessage());
                    }
                }
                commonA.setA23(sb.toString());
            }

        }
        ExcelUtil.writeExcel(commonAS, CommonA.class, "/Users/meihongliang/Downloads/A_xiaowan/download/D_儿童常用OTC77_匹配上数据_28_return.xlsx");
    }
}
